def run(working_dir=".",
        echo2d_exe_path=r"D:\Program Files (x86)\ECHO2D_v3.5\ECHO2D_v3_5\Codes\Windows_Intel_OpenMP\ECHO2D.exe"):
    """
    运行ECHO2D程序

    Parameters:
    echo2d_exe_path (str): ECHO2D.exe的完整路径
    working_dir (str): 包含input_in.txt的工作目录
    """
    import subprocess
    import os
    import time
    import threading
    # 检查ECHO2D.exe路径以及处理文件夹和文件是否存在
    if not os.path.exists(echo2d_exe_path):
        raise FileNotFoundError(f"ECHO2D.exe not found: {echo2d_exe_path}")
    if not os.path.exists(working_dir):
        raise FileNotFoundError(f"Working directory not found: {working_dir}")
    input_file = os.path.join(working_dir, "input_in.txt")
    if not os.path.exists(input_file):
        raise FileNotFoundError(f"input_in.txt not found in {working_dir}")

    print(f"正在运行 ECHO2D...")
    print(f"程序: {echo2d_exe_path}")
    print(f"工作目录: {working_dir}")

    print("-" * 50)

    # 开始计时
    start_time = time.time()
    start_time_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(start_time))
    print(f"开始时间: {start_time_str}")

    # 计时器线程函数 - 每10分钟输出一次
    def timer_thread():
        check_interval = 600.0  # 10分钟 = 600秒
        last_check = start_time

        while timer_running[0]:
            current_time = time.time()
            elapsed_since_last_check = current_time - last_check

            # 每10分钟输出一次
            if elapsed_since_last_check >= check_interval:
                total_elapsed = current_time - start_time
                total_minutes = total_elapsed / 60

                # 计算小时和分钟
                hours = int(total_minutes // 60)
                minutes = int(total_minutes % 60)
                seconds = int(total_elapsed % 60)

                if hours > 0:
                    time_str = f"{hours}小时{minutes}分钟{seconds}秒"
                else:
                    time_str = f"{minutes}分钟{seconds}秒"

                print(f"[定时报告] 已运行: {time_str} ({total_minutes:.2f} 分钟)")
                last_check = current_time

            time.sleep(30)  # 每30秒检查一次

    timer_running = [True]
    timer = threading.Thread(target=timer_thread)
    timer.daemon = True
    timer.start()

    try:
        # 运行程序
        process = subprocess.Popen(
            [echo2d_exe_path],
            cwd=working_dir,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            text=True,
            encoding='utf-8',
            errors='ignore'
        )

        # 实时输出程序输出
        print("正在执行计算，请等待...")
        stdout_lines = []

        while True:
            output = process.stdout.readline()
            if output == '' and process.poll() is not None:
                break
            if output.strip():
                cleaned_output = output.strip()
                stdout_lines.append(cleaned_output)
                print(f"[ECHO2D] {cleaned_output}")

        # 获取剩余输出
        remaining_stdout, stderr = process.communicate()
        if remaining_stdout:
            for line in remaining_stdout.splitlines():
                if line.strip():
                    stdout_lines.append(line.strip())
                    print(f"[ECHO2D] {line.strip()}")

        # 停止计时器
        timer_running[0] = False
        time.sleep(1)  # 给计时器线程一点时间退出

        # 结束计时
        end_time = time.time()
        end_time_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(end_time))
        elapsed_time_seconds = end_time - start_time
        elapsed_time_minutes = elapsed_time_seconds / 60

        # 格式化最终时间显示
        hours = int(elapsed_time_minutes // 60)
        minutes = int(elapsed_time_minutes % 60)
        seconds = int(elapsed_time_seconds % 60)

        if hours > 0:
            final_time_str = f"{hours}小时{minutes}分钟{seconds}秒"
        else:
            final_time_str = f"{minutes}分钟{seconds}秒"

        print("\n" + "=" * 60)
        print(f"开始时间: {start_time_str}")
        print(f"结束时间: {end_time_str}")
        print(f"总运行时间: {final_time_str} ({elapsed_time_minutes:.2f} 分钟)")

        if process.returncode == 0:
            print("✅ ECHO2D 计算成功完成！")
        else:
            print(f"❌ ECHO2D 执行失败，返回码: {process.returncode}")
            if stderr:
                print(f"错误信息: {stderr}")

        return process.returncode, "\n".join(stdout_lines), stderr, elapsed_time_minutes

    except Exception as e:
        # 停止计时器
        timer_running[0] = False
        time.sleep(1)

        # 异常情况也计算耗时
        end_time = time.time()
        elapsed_time_minutes = (end_time - start_time) / 60

        # 格式化异常情况的时间显示
        hours = int(elapsed_time_minutes // 60)
        minutes = int(elapsed_time_minutes % 60)
        seconds = int((end_time - start_time) % 60)

        if hours > 0:
            final_time_str = f"{hours}小时{minutes}分钟{seconds}秒"
        else:
            final_time_str = f"{minutes}分钟{seconds}秒"

        print(f"\n❌ 执行过程中出错: {e}")
        print(f"运行时间: {final_time_str} ({elapsed_time_minutes:.2f} 分钟)")
        return -1, "", str(e), elapsed_time_minutes


def post_process():
    ...
